package com.authine.cloudpivot.web.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.domain.Constants;
import com.authine.cloudpivot.web.api.exception.PortalException;
import com.authine.cloudpivot.web.api.service.StoreService;
import com.authine.cloudpivot.web.api.service.XZZPXQService;
import com.authine.cloudpivot.web.api.view.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(description = "外企德科相关接口", tags = "招聘、店检需求")
@RestController
@RequestMapping("/api/xzzpxq")
@Slf4j
@Validated
public class XZZPXQController extends BaseController {

    @Autowired
    private XZZPXQService xzzpxqService;

    /**
     * 招聘、店检需求获取执行经理
     * @param
     * @return
     */
    @ApiOperation(value = "根据项目、门店，获取执行经理" )
    @GetMapping("/getExecutive")
    @ResponseBody
    public ResponseResult<?> getExecutive(String subjectName,String storeNames){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            String persons= xzzpxqService.getExecutive(subjectName,storeNames,Constants.RECRUIT);
            JSONArray person = JSONArray.fromObject(persons);
            json.put("executive",person);
            json.put("message","获取执行经理成功");
        }catch (PortalException e) {
                statusReal = 500L;
                json.put("message", "获取执行经理失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }


    /**
     * @Description : 店检需求获取督导
     * @param ： subjectName
     * @param ： storeNames
     * @author : Liun
     * @date : 2020/4/26
     */
    @ApiOperation(value = "根据项目、门店，获取督导" )
    @GetMapping("/getMember")
    @ResponseBody
    public ResponseResult<?> getMember(String subjectName,String storeNames){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            String persons= xzzpxqService.getExecutive(subjectName,storeNames, Constants.SHOP_INSPECTION);
            JSONArray person = JSONArray.fromObject(persons);
            json.put("member",person);
            json.put("message","获取督导成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "获取督导失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }





    /**
     * @Description : 根据项目、省份，获取执行经理
     * @param ： subjectName
     * @param ： provinces
     * @author : Liun
     * @date : 2020/6/8
     */
    @ApiOperation(value = "根据项目、省份，获取执行经理" )
    @GetMapping("/getExecutiveOther")
    @ResponseBody
    public ResponseResult<?> getExecutiveOther(String subjectName,String provinces){
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            String persons= xzzpxqService.getExecutiveOther(subjectName,provinces);
            JSONArray person = JSONArray.fromObject(persons);
            json.put("executive",person);
            json.put("message","获取执行经理成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "获取执行经理失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }




}
